import { _decorator, Component, EditBox, Node } from 'cc';
import ViewBase from '../../../../src/engine/ViewBase';
import { UI_Cache_Type, UI_Config } from '../../../../src/engine/UI_Config';
import { BundleConfig } from '../../../../src/config/BundleConfig';
import { EventManager } from '../../../../src/engine/EventManager';
import { UIManager } from '../../../../src/engine/UIManager';
import { ViewTip } from '../../../../src/view/ViewTip';
import { HallHttpController } from '../../controller/HallHttpController';
const { ccclass, property } = _decorator;

@ccclass('login/ViewRegister')
export class ViewRegister extends ViewBase {

    //ui 配置 
    public static uiConfig: UI_Config = new UI_Config("res/login/prefab/ViewRegister",
        UI_Cache_Type.noCache, true, BundleConfig.hall);

    private txtAccount: EditBox
    private txtPass: EditBox
    private btnQueding: Node


    protected onShow(): void {
        this.txtAccount = this.getChild(this.contentNode, "txtAccount", EditBox)
        this.txtPass = this.getChild(this.contentNode, "txtPass", EditBox)
        this.btnQueding = this.getChild(this.contentNode, "btnQueding")
        EventManager.onAddEvent(this.btnQueding, () => {
            if (this.txtAccount.string == "") {
                UIManager.instance.showTip("请输入账号!", ViewTip.TipType.Fail);
                return
            }
            if (this.txtPass.string == "") {
                UIManager.instance.showTip("请输入密码!", ViewTip.TipType.Fail)
                return
            }
            HallHttpController.accountReg(this.txtAccount.string, this.txtPass.string, (isSuc: boolean) => {
                UIManager.instance.closeViewByUiConfig(ViewRegister.uiConfig);
            })
        })
    }
}

